<?
	header('Content-Type: application/octet-stream');
	header('Content-Disposition: attachment; filename="members.csv"');
	header('Cache-Control: must-revalidate, post-check=0, pre-check=0');

	//echo"Company,FirstName,LastName,Email,Suburb,State,PostCode,Country,UserName,Password\n";
	
	include("../../classes/clsDB.php");
	$FirstRow=true;
	$FirstRowText="";
	$r=new ReturnRecord();
	$sq2=$r->rawQuery("SELECT * FROM members");  
	while ($myrow = mysql_fetch_assoc($sq2)) {
		$FirstColumn=true;
		$RowText="";
		foreach($myrow as $key=>$val){
			$seperator=($FirstColumn ? "" : ",");
			if($FirstRow){
				$FirstRowText.=$seperator.$key;
			}
			$RowText.=$seperator.$val;
			$FirstColumn=false;
		}
		if($FirstRow){
			$RowText=$FirstRowText."\n".$RowText."\n";
		}else{
			$RowText.="\n";
		}
		
		print $RowText;
		
		$FirstRow=false;
	};
?>